package com.example.yurpceasy.register;

import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.kv.GetResponse;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class EtcdDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Client client = Client.builder().endpoints("http://localhost:2379").build();
        KV kvClient = client.getKVClient();

        ByteSequence key = ByteSequence.from("test_key".getBytes());
        ByteSequence val = ByteSequence.from("test_value".getBytes());

        // put
        kvClient.put(key,val).get();

        // get
        CompletableFuture<GetResponse> future = kvClient.get(key);
        GetResponse response = future.get();
        System.out.println(response);

        // delete
        kvClient.delete(key).get();
    }
}
